package com.tz;

import org.hibernate.cfg.Configuration;
import org.hibernate.tool.hbm2ddl.SchemaExport;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.orm.hibernate4.LocalSessionFactoryBean;


/**
 * Created by Tinyang on 2016/7/27.
 */
public class InitTable {
    @Test
    public void testDDL() {
        ApplicationContext ac = new AnnotationConfigApplicationContext(AppConfig.class);
        LocalSessionFactoryBean lsfb=ac.getBean(LocalSessionFactoryBean.class);
        Configuration cfg=lsfb.getConfiguration();
        SchemaExport se = new SchemaExport(cfg);
        //第一个参:sql脚本是否输出到控制台
        //第二个参:sql脚本是否导入到数据库
        se.create(true, true);
    }

}
